<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>

<html>
<head>
    <title>待分配任务</title>
    <meta name="menu" content="queuedTasks"/>

    <script type="text/javascript">
          $(document).ready(function(){
              $("#processDefinitionName,#dueDateFlag").change(function(){
                    searchPage();
              });

              $("#excelExport").click(function(){
                  var mainForm = $("#mainForm");
                  mainForm.attr("action","task!queuedExp.action");
                  mainForm.submit();
                  mainForm.attr("action","task!queued.action");
              }) ;

              $("#dialog").dialog({
                    bgiframe: true,
                    autoOpen: false,
                    width:250,
                    modal: true
                  });

              $('#closeDialogButton').click(function() {
                  $('#dialog').dialog('close');
              });

              $("#assignTaskButton").click(function(){
                  $("#mainForm").attr("action","task!assign.action");
                  $("#mainForm").submit();
              }) ;

              $("#assigneeSelect").change(function(){
                  $("#assignee").val($(this).val());
              })
          })

          function openDialog(taskId, subject) {
              $("#dialog #taskName").val(subject);
              $("#mainForm #taskId").val(taskId);
              var selector = $("#assigneeSelect");
              selector.empty();
              selector.focus();
              $.ajax({
                         type:"post",
                         url: "${ctx}/workflow/task!getTaskCandidateUsers.action",
                         data:"taskId=" + taskId,
                         error:function(error) {
                             alert(error);
                         } ,
                         success:function (output) {
                             if(output){
                                 $.each(output, function(i){
                                     selector.append(('<option value="'+output[i].userId+'">'+output[i].firstName+'</option>'));
                                 }),
                               selector.change();
                               $('#dialog').dialog('open');
                             }
                         }
                     });
          }
    </script>

</head>

<body>

<div id="dialog" title="分配任务">
        <p>
            <label for="taskName" class="inline">任务名:</label>
            <input type="text" id="taskName" name="taskName" readonly="true" class="input-small">
        </p>
        <p>
            <label for="assigneeSelect" class="inline">分配人:</label>
            <select id="assigneeSelect"  class="input-small">
            </select>
        </p>
        <p>
            <a href="#"  id="assignTaskButton" class="button">确认分配</a>
            <a href="#"  id="closeDialogButton" class="button">取消</a>
        </p>
</div>

<div class="content_block">
    <%@ include file="/common/messages.jsp" %>
    <h2 class="jquery_tab_title">待分配任务</h2>

    <form action="task!queued.action" method="post" id="mainForm">
        <input type="hidden" id="fileDownloadToken" name="fileDownloadToken">
        <input type="hidden" id="taskId" name="taskId" class="input-small">
        <input type="hidden" id="assignee" name="assignee" class="input-small">
        <div>
            <p>
                <label class="inline">流程名:</label>
                <code:dispCodeList id="processDefinitionName" name="filter.processDefinitionName" table="ACT_RE_PROCDEF" codeColumn="NAME_"
                                   valueColumn="NAME_"
                                   codeValue="${filter.processDefinitionName}" displayHeader="true"/>
                <label class="inline">创建人:</label>
                <input name="filter.initiatorNameLike" type="text" value="${filter.initiatorNameLike}"
                       class="input-small"/>
                <label class="inline">创建时间 从:</label>
                <input class="input-small flexy_datepicker_input" type="text" name="filter.startTimeFrom"
                       value="<s:date name='filter.startTimeFrom' format='yyyy-MM-dd'/>">
                <label class="inline">到:</label>
                <input class="input-small flexy_datepicker_input" type="text" name="filter.startTimeTo"
                       value="<s:date name='filter.startTimeTo' format='yyyy-MM-dd'/>">
                是否过期：
                <code:dispCodeList id="dueDateFlag" name="filter.dueDateFlag" codeType="DUE_DATE_FLAG"  displayHeader="true" codeValue="${filter.dueDateFlag}" />
                <a href="#" class="button" onclick="searchPage()">查询</a>
            </p>
            <table width="100%" cellpadding="0" id="table_liquid" cellspacing="0">
                <thead>
                <tr>
                    <th><a href="javascript:sort('D.NAME_','asc')" scope="col">流程名</a></th>
                    <th><a href="javascript:sort('subjectVariable.TEXT_','asc')" scope="col">任务名</a></th>
                    <th><a href="javascript:sort('initiatorUser.first_','asc')" scope="col">创建人</a></th>
                    <th><a href="javascript:sort('T.create_time_','asc')" scope="col">创建时间</a></th>
                    <th><a href="javascript:sort('T.due_date_','asc')" scope="col">过期时间</a></th>
                    <th><a href="javascript:sort('T.NAME_','asc')" scope="col">当前状态</a></th>
                    <th style="max-width: 150px" >操作</th>
                </tr>
                </thead>
                <tbody>
                <s:iterator value="page.result">
                    <tr <c:if test="${overDue}"> class="warn"</c:if>>
                        <td>${processDefinitionName}&nbsp;</td>
                        <td><stringDisplay:short length="10" fullText="${subject}"/>&nbsp;</td>
                        <td>${initiatorName}&nbsp;</td>
                        <td><fmt:formatDate value="${createTime}" pattern="yyyy/MM/dd"/>&nbsp;</td>
                        <td><fmt:formatDate value="${dueDate}" pattern="yyyy/MM/dd"/>&nbsp;</td>
                        <td>${name}&nbsp;</td>
                        <td>
                            <a href='<s:url value="%{getFormKey(id)}"/>?taskId=${id}&currentMenu=queuedTasks'>查看</a>&nbsp;
                            <c:if test="${assignee==null}">
                                <a href="task!claim.action?taskId=${id}">领取任务</a>&nbsp;
                            </c:if>
                            <security:authorize ifAnyGranted="A_分配任务">
                                <a href="#" id="openDialogButton" onclick="openDialog('${id}','${subject}')">分配任务</a>
                            </security:authorize>
                        </td>
                    </tr>
                </s:iterator>
                <tr>
                    <td colspan="2" class="tdButton">
                    <c:if test="${page.totalCount>0}">
                    <a href="#"  id="excelExport" class="button">导出Excel</a>
                     </c:if>
                    </td>
                    <td colspan="9" class="pagination">
                        <%@ include file="/common/pagination.jsp" %>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
</div>
<!--end content_block-->

</body>
</html>
